package com.wwz.leetcode;

import com.wwz.common.ListNode;
import org.junit.Test;

/**
 * 执行用时：0 ms, 在所有Java提交中击败了100.00%的用户
 * 内存消耗：40.3 MB, 在所有Java提交中击败了25.72%的用户
 */
public class LeetCode24 {
    @Test
    public void test(){
        reverseList(new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5,null))))));
    }
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode next = null;
        while(head != null){
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
}
